import java.io.*;
import java.net.Socket;

public class ChatChannel implements Runnable{
    Socket socket;

    public ChatChannel(Socket socket){
        this.socket = socket;
    }
    @Override
    public void run() {
        try {
            InputStream is = socket.getInputStream();
            ObjectInputStream ois = new ObjectInputStream(is);
            String name = (String) ois.readObject();
            System.out.println(name + "进入聊天室");
            OutputStream os = socket.getOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(os);
            oos.writeObject(name + ",您好！欢迎您进入聊天室");

            while (true){
                oos.writeObject(name+"说:"+ois.readObject());
            }
        }
        catch(IOException e){
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
